import java.io.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-10
 * Time: 15:00
 */
public class demo4 {

    //实现文件复制,也就是把文件中每个字节读取,写入另一个文件中

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入源文件路径");
        String src = scanner.next();
        File srcFile = new File(src);

        if (srcFile.isFile()) {
            System.out.println("文件不存在");
            return;
        }

        System.out.println("请输入目标文件");
        String dest = scanner.next();
        File destFile = new File(dest);
        byte[] buffer = new byte[1024];
        try (InputStream inputStream = new FileInputStream(srcFile);
             OutputStream outputStream = new FileOutputStream(destFile)
        ) {
            int n = 0;
            while (true) {
                n = inputStream.read(buffer);
                if (n == -1) {
                    break;
                }
                outputStream.write(buffer, 0, n);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
